﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using ZQNB.Common.Caching;
using ZQNB.Common.Ioc;

namespace ZQNB.Web.Common.Controllers
{
    public class TestController : Controller
    {
        // demo: rpcapi/Test/GetById/1
        // demo: api/Test/1
        public JsonResult GetById(int id)
        {
            IPerSessionCacheManager perSessionCacheManager = CoreServiceProvider.LocateService<IPerSessionCacheManager>();
            var date = perSessionCacheManager.Get<string>("test");
            if (date == null)
            {
                date = DateTime.Now.ToString();
                perSessionCacheManager.Set("test", date);
            }
            var result = "[MVC] GetById from session : " + date + ", page refresh at : " + DateTime.Now;
            return Json(result, JsonRequestBehavior.AllowGet);
        }

        public JsonResult GetByName(string name)
        {
            IPerSessionCacheManager perSessionCacheManager = CoreServiceProvider.LocateService<IPerSessionCacheManager>();
            var date = perSessionCacheManager.Get<string>("test");
            if (date == null)
            {
                date = DateTime.Now.ToString();
                perSessionCacheManager.Set("test", date);
            }
            var result = "[MVC] GetByName from session : " + date + ", page refresh at : " + DateTime.Now;
            return Json(result, JsonRequestBehavior.AllowGet);
        }
    }
}
